package org.qy137.controller;

import com.qy137.entity.Banner;
import org.qy137.service.LunBoService;
import org.qy137.utils.CommonResult;
import com.qy137.vo.BannerVo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiOperation;
import org.qy137.utils.OSSUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;


@RestController
@RequestMapping("lunbo")
@ApiModel(value="封装返回客户端的数据实体")
public class LunBoController {
    @Autowired
    private LunBoService lunBoService;

    @ApiOperation(value = "后台管理轮播图信息")
    @GetMapping("getAlllubbotu/{page}/{limit}")
    public CommonResult getAlllubbotu(@PathVariable("page") Integer page,
                                      @PathVariable("limit") Integer limit,
                                      @RequestBody(required = false) BannerVo bannerVo){
        return lunBoService.getAlllubbotu(page,limit,bannerVo);
    }
    @ApiOperation(value = "逻辑删除轮播图（1，删除。2，未删除）")
    @DeleteMapping("deleteBanner")
    public CommonResult deleteBanner(@RequestBody BannerVo bannerVo){
        return lunBoService.deleteBanner(bannerVo);
    }

    @ApiOperation(value = "改变轮播图的显示状态")
    @PutMapping("updataStatus/{id}/{isDisable}")
    public CommonResult updataStatus(@PathVariable("id") String id,
                                     @PathVariable("isDisable") Integer isDisable){
        return lunBoService.updataStatus(id,isDisable);
    }

    @ApiOperation(value = "添加或修改轮播图")
    @PostMapping("addBanner")
    public CommonResult addBanner(@RequestBody Banner banner){
        return lunBoService.addBanner(banner);
    }

    @ApiOperation(value = "上传轮播图图片")
    @PostMapping("uploadMsg")
    public StringBuffer uploadMsg(MultipartFile file){
        return OSSUtil.getOssUrl(file);

    }
}
